import os
import sys

from loguru import logger


from settings.constant import p_path
from common.ConfigUtil import config


class LoggerUtil:
    def __init__(self, level, info_log, err_log):
        self.level = level
        self.info_log = info_log
        self.err_log = err_log

    def log(self):
        info_log_file_path = os.path.join(p_path.LOG_PATH, self.info_log)
        err_log_file_path = os.path.join(p_path.LOG_PATH, self.err_log)

        logger.add(sys.stderr, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",
                   filter="my_module", level=self.level,
                   enqueue=True, serialize=True)
        logger.add(info_log_file_path, rotation="50 MB", encoding='utf-8')
        logger.add(err_log_file_path, rotation="50 MB", encoding='utf-8',
                   level='ERROR')
        return logger


log = LoggerUtil(config.read('logger', 'level'),
                 config.read('logger', 'info_log'),
                 config.read('logger', 'err_log')
                 ).log()

if __name__ == '__main__':
    log.info('test--info---')
    log.error('test--error----')









